{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8c9fb456",
   "metadata": {},
   "source": [
    "-------\n",
    "* 2022-11-2/week03\n",
    "* 课程：Python\n",
    "* 记录人：zhoubilian\n",
    "-------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "55c11d1f",
   "metadata": {},
   "source": [
    "> 1. 元组\n",
    "> 2. \n",
    "> 3. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7577d3ad",
   "metadata": {},
   "source": [
    "# 1. 元组(tuple)\n",
    "> 1. 元组的概念和基本形态\n",
    "> 2. 元组的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b4a5696c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1800001, 1800002, 1800003) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "user_infor=1800001,1800002,1800003\n",
    "print(user_infor,type(user_infor))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "29617b44",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1800001, 1800002, 1800003] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "user_infor_list=[1800001,1800002,1800003]\n",
    "print(user_infor_list,type(user_infor_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "59b36a1b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1800001\n",
      "(1800001, 1800002)\n"
     ]
    }
   ],
   "source": [
    "#取值\n",
    "print(user_infor[0])\n",
    "#切片\n",
    "print(user_infor[:2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3b1172eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c4307cf7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=11, tm_mday=2, tm_hour=19, tm_min=11, tm_sec=24, tm_wday=2, tm_yday=306, tm_isdst=0)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "38e2c937",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on struct_time object:\n",
      "\n",
      "class struct_time(builtins.tuple)\n",
      " |  struct_time(iterable=(), /)\n",
      " |  \n",
      " |  The time value as returned by gmtime(), localtime(), and strptime(), and\n",
      " |  accepted by asctime(), mktime() and strftime().  May be considered as a\n",
      " |  sequence of 9 integers.\n",
      " |  \n",
      " |  Note that several fields' values are not the same as those defined by\n",
      " |  the C language standard for struct tm.  For example, the value of the\n",
      " |  field tm_year is the actual year, not year - 1900.  See individual\n",
      " |  fields' descriptions for details.\n",
      " |  \n",
      " |  Method resolution order:\n",
      " |      struct_time\n",
      " |      builtins.tuple\n",
      " |      builtins.object\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __reduce__(...)\n",
      " |      Helper for pickle.\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data descriptors defined here:\n",
      " |  \n",
      " |  tm_gmtoff\n",
      " |      offset from UTC in seconds\n",
      " |  \n",
      " |  tm_hour\n",
      " |      hours, range [0, 23]\n",
      " |  \n",
      " |  tm_isdst\n",
      " |      1 if summer time is in effect, 0 if not, and -1 if unknown\n",
      " |  \n",
      " |  tm_mday\n",
      " |      day of month, range [1, 31]\n",
      " |  \n",
      " |  tm_min\n",
      " |      minutes, range [0, 59]\n",
      " |  \n",
      " |  tm_mon\n",
      " |      month of year, range [1, 12]\n",
      " |  \n",
      " |  tm_sec\n",
      " |      seconds, range [0, 61])\n",
      " |  \n",
      " |  tm_wday\n",
      " |      day of week, range [0, 6], Monday is 0\n",
      " |  \n",
      " |  tm_yday\n",
      " |      day of year, range [1, 366]\n",
      " |  \n",
      " |  tm_year\n",
      " |      year, for example, 1993\n",
      " |  \n",
      " |  tm_zone\n",
      " |      abbreviation of timezone name\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data and other attributes defined here:\n",
      " |  \n",
      " |  n_fields = 11\n",
      " |  \n",
      " |  n_sequence_fields = 9\n",
      " |  \n",
      " |  n_unnamed_fields = 0\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Methods inherited from builtins.tuple:\n",
      " |  \n",
      " |  __add__(self, value, /)\n",
      " |      Return self+value.\n",
      " |  \n",
      " |  __contains__(self, key, /)\n",
      " |      Return key in self.\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __getitem__(self, key, /)\n",
      " |      Return self[key].\n",
      " |  \n",
      " |  __getnewargs__(self, /)\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __hash__(self, /)\n",
      " |      Return hash(self).\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __mul__(self, value, /)\n",
      " |      Return self*value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __rmul__(self, value, /)\n",
      " |      Return value*self.\n",
      " |  \n",
      " |  count(self, value, /)\n",
      " |      Return number of occurrences of value.\n",
      " |  \n",
      " |  index(self, value, start=0, stop=9223372036854775807, /)\n",
      " |      Return first index of value.\n",
      " |      \n",
      " |      Raises ValueError if the value is not present.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Class methods inherited from builtins.tuple:\n",
      " |  \n",
      " |  __class_getitem__(...) from builtins.type\n",
      " |      See PEP 585\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help (time.localtime())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "8f16a2df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1667387616.5393238"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.time()# 可以记录互联网当中所有数据产生、销毁、创建一系列行为"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "136f6d4f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_infor.count(1800001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "90da5647",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_infor.index(1800001)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0688b496",
   "metadata": {},
   "source": [
    "## 2.集合\n",
    "> 1. 集合的概念和性质\n",
    ">> 1. 集合的唯一性\n",
    ">> 2. 集合无序性\n",
    "> 2.集合的方法\n",
    ">> 1. 交集：逻辑运算符：  setA & setB ,setA.intersetion(B)=》 应用：推荐系统\n",
    ">> 2. 并集：逻辑运算符：  setA | setB ，setA.union(B)=》 应用：快速统计两个集合元素的个数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "80a4ee25",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'orange', 'apple', 'pear', 'banana'} <class 'set'>\n"
     ]
    }
   ],
   "source": [
    "basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}\n",
    "print(basket,type(basket))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "dc7c4b8b",
   "metadata": {},
   "outputs": [],
   "source": [
    "舞蹈社_user_id={1800002,1800003,1800111,1800122}\n",
    "合唱团_user_id={1800003,1800009,1800007,1800111,1801111}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "4977a3e0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800003, 1800111}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id & 合唱团_user_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "65cc0822",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800003, 1800111}"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id.intersection (合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "8200923d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社_user_id | 合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "19fcb778",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800002, 1800003, 1800007, 1800009, 1800111, 1800122, 1801111}"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id.union(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "858c9c76",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考：如果是列表的话，想要找出重复的项？集合的价值\n",
    "舞蹈社_user_id={1800002,1800003,1800111,1800122}\n",
    "合唱团_user_id={1800003,1800009,1800007,1800111,1801111}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18304fbd",
   "metadata": {},
   "source": [
    "## 3.字典（dict）\n",
    "> 1. 字典的概念和性质\n",
    ">> 1. 性质\n",
    ">>> 1. 无序性\n",
    ">>> 2. key是唯一的（没有重复）\n",
    ">>> 3. key是不可变的\n",
    "\n",
    "> 2. 字典的创建\n",
    ">> 1. 按照字典的形态创建字典\n",
    "```\n",
    "网新1班={\n",
    "    1800001:\"billion\",\n",
    "    1800002:\"panwenjing\",\n",
    "    1800003:\"liyuanyuan\",\n",
    "    1800004:\"Marry\"\n",
    "}\n",
    "```\n",
    ">> 2. 使用dict()方法创建字典\n",
    "```\n",
    "网新2班=dict（\n",
    "    stu1900001=\"小红\",\n",
    "    stu1900002=\"小蓝\",\n",
    "    stu1900003=\"小绿\",\n",
    "    stu1900004=\"小紫\"\n",
    "）\n",
    "```\n",
    "> 3. 字典的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "5bcdb70c",
   "metadata": {},
   "outputs": [],
   "source": [
    " wechat={\n",
    "     \"qwyuhuhisd\":[\"billion\",\"冰岛\",\"朋友圈\",\"点赞\",\"评论\",\"置顶\"],\n",
    "     \"zxcvnmoqwe\":[\"Jack\",\"HongKong\"]\n",
    " }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "fe0bf66c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['billion', '冰岛', '朋友圈', '点赞', '评论', '置顶']"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wechat[\"qwyuhuhisd\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "27b8d7ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新1班={\n",
    "    1800001:\"billion\",\n",
    "    1800002:\"panwenjing\",\n",
    "    1800003:\"liyuanyuan\",\n",
    "    1800004:\"Marry\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "6602f227",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1800001: 'billion', 1800002: 'panwenjing', 1800003: 'liyuanyuan', 1800004: 'Marry'} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "print(网新1班,type(网新1班))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "64a6819e",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新2班=dict(\n",
    "    stu1900001=\"小红\",\n",
    "    stu1900002=\"小蓝\",\n",
    "    stu1900003=\"小绿\",\n",
    "    stu1900004=\"小紫\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "c194a8aa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu1900001': '小红', 'stu1900002': '小蓝', 'stu1900003': '小绿', 'stu1900004': '小紫'} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "print(网新2班,type(网新2班))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6011098e",
   "metadata": {},
   "source": [
    "* 请取出stu1900002的结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "5483bc03",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'小蓝'"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网新2班[\"stu1900002\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "420e193e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
